package main

import (
	"encoding/json"
	"fmt"
)

type people struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}

func main() {
	p1 := people{
		Name: "李杰",
		Age:  50,
	}
	b, err := json.Marshal(p1)
	if err != nil {
		fmt.Println("marshal failed")
		return
	}
	fmt.Println(string(b))
	//反序列化
	var p3 people
	json.Unmarshal([]byte(b), &p3)
	fmt.Printf("%#v", p3)
}
